import {
	getJobNumber
} from "@/api/specialWork/hotWork.js"
import {
	hotWorkTerm,
	groundWorkTerm,
	heightWorkTerm,
	liftWorkTerm,
	spaceSafeTerm,
	temporarySafeTerm,
	turnOffSafeTerm,
	bindPlateWorkTerm
} from "@/pages/specialWork/confirmItem/index.js"


// 九大作业类型流程的对应展示按钮
export const workTypeFlowBtn = (status, type) => {
	if (status == 1) {
		return "作业申请";
	} else if (status == 2) {
		return "措施填写";
	} else if (status == 3) {
		return "措施确认";
	} else if (status == 4) {
		return "现场确认";
	} else if (status == 5) {
		return "审核";
	} else if (
		(status == 6 && type == "动火作业票") ||
		type == "受限空间安全作业票"
	) {
		return "作业分析";
	} else if (status == 6 && type != "动火作业票") {
		return "指定签字人";
	} else if (status == 7) {
		return "结束作业";
	} else if (status == 1001) {
		return "已完结";
	}
}

//9大特殊作业作业票号
export const formatJobNum = async (jobType) => {
	let res = await getJobNumber();
	switch (jobType) {
		case "动火作业票":
			return `DH${res}`;

		case "动土作业票":
			return `DT${res}`;

		case "吊装作业票":
			return `DZ${res}`;

		case "断路作业票":
			return `DL${res}`;

		case "高处作业票":
			return `GC${res}`;
		case "临时用电安全作业票":
			return `LSYD${res}`;
		case "盲板抽堵安全作业票":
			return `MBCD${res}`;
		case "受限空间安全作业票":
			return `SXAQ${res}`;
	}
}

//9大作业票提交参数格式化
export const formatJobQuery = (jobType, submitForm) => {
	switch (jobType) {
		case "动火作业票":
			submitForm.hotMode = JSON.stringify(submitForm.hotMode);
			//风险辨识
			submitForm.riskIdentification = JSON.stringify(
				submitForm.riskIdentification
			);
			//其他特殊作业
			submitForm.associateOthers = JSON.stringify(
				submitForm.associateOthers
			);
			//动火人
			submitForm.iratePerson = JSON.stringify(
				submitForm.iratePerson
			);
			//特殊作业类型
			submitForm.specialJobType = jobType

			return submitForm;
		case "动土作业票":
			//风险辨识
			submitForm.riskIdentification = JSON.stringify(
				submitForm.riskIdentification
			);
			//其他特殊作业
			submitForm.associateOthers = JSON.stringify(
				submitForm.associateOthers
			);
			//作业人
			submitForm.iratePerson = JSON.stringify(
				submitForm.iratePerson
			);
			//动土示意图
			submitForm.workFileList = JSON.stringify(
				submitForm.workFileList
			);
			//特殊作业类型
			submitForm.specialJobType = jobType

			return submitForm;
			//其他特殊作业
		default:
			//作业人
			submitForm.workPerson = JSON.stringify(submitForm.workPerson);
			//风险辨识
			submitForm.riskIdentification = JSON.stringify(
				submitForm.riskIdentification
			);
			//其他特殊作业
			submitForm.associateOthers = JSON.stringify(
				submitForm.associateOthers
			);
			//特殊作业类型
			submitForm.specialJobType = jobType

			return submitForm;





	}
}

//9大作业类型返回不同的措施确认项
export const foramtConfirmItem = (jobType) => {
	switch (jobType) {
		case "动火作业票":
			return hotWorkTerm();

		case "动土作业票":
			return groundWorkTerm();

		case "吊装作业票":
			return liftWorkTerm();

		case "断路作业票":
			return turnOffSafeTerm();

		case "高处作业票":
			return heightWorkTerm();
		case "临时用电安全作业票":
			return temporarySafeTerm();
		case "盲板抽堵安全作业票":
			return bindPlateWorkTerm();
		case "受限空间安全作业票":
			return spaceSafeTerm();
	}
}

//签字人的上传的type】
/**
 * @param 
 * jobType 作业类型
 * typeTitle 流程步骤
 * response 上传文件数据
 * status 根据status值  选择上传类型的type
 **/
export const formatType = (jobType, typeTitle, response, status, signTitle) => {
	response.fileId = response.id
	delete response.code
	delete response.msg
	delete response.systemTime

	if (typeTitle == '措施填写') {
		response.type = "42" // 编制人签字
		response.fileId = response.id
		delete response.code
		delete response.msg
		delete response.systemTime

		return response
	} else if (typeTitle == '措施确认') {
		if (jobType == "动火作业票") {
			response.type = "32" // 动火负责人签字
			response.fileId = response.id
			delete response.code
			delete response.msg
			delete response.systemTime
			return response
		} else {
			response.type = "35" // 监护人签字
			response.fileId = response.id
			delete response.code
			delete response.msg
			delete response.systemTime
			return response

		}
	} else if (typeTitle == '现场确认') {
		if (status == '0') { //安全交底人签字
			response.type = "33"
			response.fileId = response.id
			delete response.code
			delete response.msg
			delete response.systemTime
			return response
		} else if (status == '1') { //接受交底人
			response.type = "34"
			response.fileId = response.id
			delete response.code
			delete response.msg
			delete response.systemTime
			return response
		} else if (status == '2') { //动火监护人
			response.type = "35"
			response.fileId = response.id
			delete response.code
			delete response.msg
			delete response.systemTime
			return response
		}
	} else if (typeTitle == '审核') {
		console.log("signTitle", signTitle)
		//根据不同作业票上传不同的图片类型
		if (signTitle == "区域管理部门审批") {

			response.type = "37";
			return response

		} else if (signTitle == "综合办公室会签") {
			response.type = "50";
			return response
		} else if (signTitle == "区域管理部门意见" ||
			signTitle == "区域管理部门审批") {
			response.type = "37";
			return response
		} else if (signTitle == "作业区域管理部门意见" || signTitle == "作业区域管理部门审批") {
			response.type = "45";
			return response
		} else if (signTitle == "作业管理部门意见" || signTitle == "作业管理部门审批") {
			response.type = "38";
			return response
		} else if (signTitle == "吊装指挥意见") {
			response.type = "43";
			return response
		} else if (
			signTitle ==
			"设备管理部核查情况(地面标志、动土区域管线、电缆敷设情况、对周边建筑物影响等)"
		) {
			response.type = "46";
			return response
		} else if (signTitle == "作业负责人意见") {
			response.type = "52";
			return response
		} else if (response == "设备管理部门意见(二级,三级)" || response == "设备管理部门意见" || response == "设备管理部门意见(二级,三级)" ||
			response == "设备管理部门意见") {
			response.type = "44";
			return response
		} else if (response == "配送电管理部门意见") {
			response.type = "49";
			return response
		} else if (response == "项目归口管理部门审批") {
			response.type = "51";
			return response
		} else if (response == "公司领导意见" || response == "公司领导意见(一级)" || response == "公司领导意见(特级)") {
			response.type = "40";
			return response
		}

	} else if (typeTitle == '结束作业') {
		response.type = "41";
		return response
	}

}
//根据不同作业票取值不同object
export const formatObject = (specialJobType, level) => {
	if (level == "inner") {
		switch (specialJobType) {
			case "动火作业票":
				return "fireVo";

			case "受限空间安全作业票":
				return "restrictedVo";
			case "吊装作业票":
				return "liftingVo";
			case "高处作业票":
				return "heightVo";
			case "动土作业票":
				return "groundVo";
			case "盲板抽堵安全作业票":
				return "bindPlateVo";
			case "断路作业票":
				return "turnOffVo";
			case "临时用电安全作业票":
				return "temporaryVo";

			default:
				break;
		}
	} else if (level == "out") {
		switch (specialJobType) {
			case "动火作业票":
				return [
					"fireOne",
					"fireTwo",
					"fireThree",
					"fireFour",
					"fireFive",
					"fireSix",
					"fireSeven",
				];

			case "受限空间安全作业票":
				return [
					"restrictedOne",
					"restrictedTwo",
					"restrictedThree",
					"restrictedFour",
					"restrictedFive",
					"restrictedSix",
					"restrictedSeven",
				];
			case "吊装作业票":
				return [
					"liftingOne",
					"liftingTwo",
					"liftingThree",
					"liftingFour",
					"liftingFive",
					"liftingSix",
					"liftingSeven",
				];

			case "高处作业票":
				return [
					"heightOne",
					"heightTwo",
					"heightThree",
					"heightFour",
					"heightFive",
					"heightSix",
					"heightSeven",
				];

			case "动土作业票":
				return [
					"groundOne",
					"groundTwo",
					"groundThree",
					"groundFour",
					"groundFive",
					"groundSix",
					"groundSeven",
				];

			case "盲板抽堵安全作业票":
				return [
					"bindPlateOne",
					"bindPlateTwo",
					"bindPlateThree",
					"bindPlateFour",
					"bindPlateFive",
					"bindPlateSix",
					"bindPlateSeven",
				];

			case "断路作业票":
				return [
					"turnOffOne",
					"turnOffTwo",
					"turnOffThree",
					"turnOffFour",
					"turnOffFive",
					"turnOffSix",
					"turnOffSeven",
				];
			case "临时用电安全作业票":
				return [
					"temporaryOne",
					"temporaryTwo",
					"temporaryThree",
					"temporaryFour",
					"temporaryFive",
					"temporarySix",
					"temporarySeven",
				];
			default:
				break;
		}
	}
}


//特殊作业审批流程步骤
export const jobProcessTitle = (specialJobType, level) => {
	if (specialJobType == "动火作业票") {
		if (level == 0) {
			return [
				"区域管理部门审批",
				"作业管理部门审批",
				"安全环保部门审批",
				"公司领导意见",
			];
		} else if (level == 1) {

			return ["区域管理部门审批", "作业管理部门审批", "安全环保部门审批"];
		} else if (level == 2) {
			return ["区域管理部门审批", "作业管理部门审批"];
		}
	} else if (specialJobType == "动土作业票") {
		return [
			"设备管理部核查情况(地面标志、动土区域管线、电缆敷设情况、对周边建筑物影响等)",
			"区域管理部门审批",
			"安全管理部门意见",
			"设备管理部门意见",
		];
	} else if (specialJobType == "吊装作业票") {
		if (level == 1) {
			return [
				"吊装指挥意见",
				"作业区域管理部门意见",
				"设备管理部门意见(二级,三级)",
				"公司领导意见(一级)",
			];
		} else if (level == 2 || level == 3) {
			return [
				"吊装指挥意见",
				"作业区域管理部门意见",
				"设备管理部门意见(二级,三级)",
			];
		}
	} else if (specialJobType == "断路作业票") {
		return [
			"作业区域管理部门审批",
			"综合办公室会签",
			"安全管理部门审批",
			"项目归口管理部门审批",
		];
	} else if (specialJobType == "高处作业票") {
		return [
			"区域管理部门审批",
			"作业管理部门审批(一级高空作业)",
			"设备管理部门意见(二级,三级)",
			"公司领导意见(特级)",
		];
	} else if (specialJobType == "临时用电安全作业票") {

		return [
			"作业负责人意见",
			"区域管理部门审批",
			"配送电管理部门意见",
			"公司领导意见",
		];
	} else if (specialJobType == "盲板抽堵安全作业票") {
		return [
			"作业管理部门意见",
			"区域管理部门意见",
			"设备管理部门意见",
		];
	} else if (specialJobType == "受限空间安全作业票") {
		return [
			"区域管理部门审批",
			"作业管理部门审批",
			"安全环保部门审批",
		];
	}
}


//组件上面流程的标题(有作业分析的)
export const haveAnalysisTitle = () => {
	return [
		"作业申请",
		"措施填写",
		"措施填写",
		"现场确认",
		"审核",
		"作业分析",
		"结束作业",
	];
};
//组件上面流程的标题（没有作业分析的）
export const noAnalysisTitle = () => {
	return [
		"作业申请",
		"措施填写",
		"措施填写",
		"现场确认",
		"审核",
		"指定签字人",
		"结束作业",
	];
};